#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Program {
    int start, end;
};

int main() {
    int n;
    cin >> n;
    
    vector<Program> programs(n);
    for (int i = 0; i < n; i++) {
        cin >> programs[i].start >> programs[i].end;
    }
    
    // 按结束时间排序
    sort(programs.begin(), programs.end(), [](const Program& a, const Program& b) {
        return a.end < b.end;
    });
    
    int count = 0;
    int lastEnd = 0;
    
    for (const auto& program : programs) {
        if (program.start >= lastEnd) {
            count++;
            lastEnd = program.end;
        }
    }
    
    cout << count << endl;
    
    return 0;
}
